(function() {"use strict";var __module = CC_EDITOR ? module : {exports:{}};var __filename = 'preview-scripts/assets/Script/taskPrefab.js';var __require = CC_EDITOR ? function (request) {return cc.require(request, require);} : function (request) {return cc.require(request, __filename);};function __define (exports, require, module) {"use strict";
cc._RF.push(module, '23db5sjZ7lB9YDMd/L3W42a', 'taskPrefab', __filename);
// Script/taskPrefab.js

"use strict";

var _XmlHttpTool = require("./XmlHttpTool");

var _XmlHttpTool2 = _interopRequireDefault(_XmlHttpTool);

var _taskScrollview = require("./taskScrollview");

var _taskScrollview2 = _interopRequireDefault(_taskScrollview);

var _allVariable = require("./allVariable");

var _allVariable2 = _interopRequireDefault(_allVariable);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

cc.Class({
    extends: cc.Component,

    properties: {
        headSprite: cc.Node,
        nameLabel: cc.Label,
        descLabel: cc.Label,
        sureBtn: cc.Button,
        noprogress: cc.Node,
        alreadtprogress: cc.Node,
        progressLabel: cc.Label,
        alreadyGet: cc.Node,
        starttaskBtn: cc.Button,
        alreadygetSign: cc.Node,
        taskdoingBtn: cc.Button,
        backGrondImage: cc.Node,
        taskDic: "",
        taskScrollViewJs: _taskScrollview2.default,
        showHubProjess: cc.Node,
        SvprogressPrefab: cc.Prefab

    },

    startTaskClick: function startTaskClick() {
        var _this2 = this;

        console.log("去做任务");
        var _this = this;
        if (_allVariable2.default.allvideoAD) {

            _allVariable2.default.allvideoAD.offClose();
            _allVariable2.default.allvideoAD.offError();
            _allVariable2.default.allvideoAD.onClose(function (res) {
                if (res && res.isEnded || res === undefined) {
                    var that = _this2;

                    _XmlHttpTool2.default.NhttpPost("/house/task_finish", { "task_id": that.taskDic["id"] }, function (res) {

                        var mainNode = cc.find("Canvas/MainCamera/taskAllView/taskScrollview/view/content");
                        mainNode.getComponent("taskScrollview").init();
                        var startgameNode = cc.find("Canvas/MainCamera/StartGameView");
                        startgameNode.getComponent("StartGameView").getUserInfoMessage();
                        startgameNode.getComponent("StartGameView").notifyPrize();
                    });
                } else {
                    // 播放中途退出，不下发游戏奖励
                    console.log("播放中途退出，不下发游戏奖d励", res);
                }
            });

            _allVariable2.default.allvideoAD.onError(function (res) {

                var errcode = res["errCode"];
                _this.tishifinde();
                if (errcode == 1004) {
                    console.log("无广告资源");
                } else {
                    console.log("无广告资源");
                }
            });

            _allVariable2.default.allvideoAD.load(function (res) {
                console.log('激励视频 广告加载成功', res);
            }).then(function () {
                return _allVariable2.default.allvideoAD.show();
            }).catch(function (err) {
                console.log('激励视频抓取结果', err);
                _this.tishifinde();
            });
        } else {

            var _this = this;
            var rewardedVideoAd = wx.createRewardedVideoAd({

                adUnitId: 'adunit-8536f460f8a4925c'

            });
            _allVariable2.default.allvideoAD = rewardedVideoAd;
            _allVariable2.default.allvideoAD.offClose();
            _allVariable2.default.allvideoAD.onClose(function (res) {
                if (res && res.isEnded || res === undefined) {
                    var that = _this2;

                    _XmlHttpTool2.default.NhttpPost("/house/task_finish", { "task_id": that.taskDic["id"] }, function (res) {

                        var mainNode = cc.find("Canvas/MainCamera/taskAllView/taskScrollview/view/content");
                        mainNode.getComponent("taskScrollview").init();
                        var startgameNode = cc.find("Canvas/MainCamera/StartGameView");
                        startgameNode.getComponent("StartGameView").getUserInfoMessage();
                        startgameNode.getComponent("StartGameView").notifyPrize();
                    });
                } else {
                    // 播放中途退出，不下发游戏奖励
                    console.log("播放中途退出，不下发游戏奖d励", res);
                }
            });

            _allVariable2.default.allvideoAD.onError(function (res) {

                var errcode = res["errCode"];
                _this.tishifinde();
                if (errcode == 1004) {

                    console.log("无广告资源");
                } else {
                    console.log("无广告资源");
                }
            });
            _allVariable2.default.allvideoAD.load(function (res) {
                console.log('激励视频 广告加载成功', res);
            }).then(function () {
                return _allVariable2.default.allvideoAD.show();
            }).catch(function (err) {
                console.log('激励视频抓取结果', err);
                _this.tishifinde();
            });
        }
    },

    // onLoad () {},


    gotoTaskClick: function gotoTaskClick() {

        console.log("领取奖励");

        var that = this;
        _XmlHttpTool2.default.NhttpPost("/marmot/task_accept", { "task_id": that.taskDic["id"] }, function (res) {

            var mainNode = cc.find("Canvas/MainCamera/taskAllView/taskScrollview/view/content");
            mainNode.getComponent("taskScrollview").init();
        });
    },

    tishifinde: function tishifinde() {
        var _this3 = this;

        if (cc.isValid(this.showHubProjess)) {
            this.showHubProjess.destroy();
        }
        this.showHubProjess = cc.instantiate(this.SvprogressPrefab);
        var taskAllViewNode = cc.find("Canvas/MainCamera/taskAllView");
        taskAllViewNode.addChild(this.showHubProjess);
        this.showHubProjess.getComponent('SVProgressView').init("今天的广告已经看完了哦！ 奖励无法领取哦。请明天再来！");
        var finish = cc.callFunc(function () {

            _this3.showHubProjess.destroy();
        }, this);
        var action = cc.sequence(cc.fadeIn(0.6), cc.delayTime(3), cc.fadeOut(1), finish);
        this.showHubProjess.runAction(action);
    },

    start: function start() {},
    init: function init(bageDic) {

        console.log("传过来的任务信息", bageDic);
        this.taskDic = bageDic;
        var that = this;
        cc.loader.load({ url: bageDic["thumbnail"], type: 'png' }, function (err, img) {

            var mylogo = new cc.SpriteFrame(img);

            that.headSprite.getComponent(cc.Sprite).spriteFrame = mylogo;

            that.headSprite.width = 106;

            that.headSprite.height = 106;
        });
        this.nameLabel.getComponent(cc.Label).string = bageDic["title"];
        this.descLabel.getComponent(cc.Label).string = bageDic["desc"];

        if (bageDic["button_status"] == 1) {
            console.log("任务未领取");
            this.starttaskBtn.node.active = true;
        } else if (bageDic["button_status"] == 2) {

            this.noprogress.active = true;
            this.alreadtprogress.active = true;
            this.taskdoingBtn.node.active = true;
            this.progressLabel.node.active = true;
            this.progressLabel.getComponent(cc.Label).string = bageDic["finish_num"] + '/' + bageDic["condition"];
            this.alreadtprogress.active = true;
            this.alreadtprogress.width = bageDic["finish_num"] / bageDic["condition"] * 116;
            this.alreadtprogress.x = -(116 - bageDic["finish_num"] / bageDic["condition"] * 116) / 2;
        } else if (bageDic["button_status"] == 3) {

            this.sureBtn.node.active = true;
            this.alreadygetSign.active = true;
            this.backGrondImage.active = true;
            var colorCode = new cc.Color(255, 255, 255, 255);
            this.nameLabel.node.color = colorCode;
            this.nameLabel.getComponent(cc.LabelOutline).color = colorCode;
            this.descLabel.node.color = colorCode;
            this.descLabel.getComponent(cc.LabelOutline).color = colorCode;
        } else {
            this.alreadyGet.active = true;
        }
    }
});

cc._RF.pop();
        }
        if (CC_EDITOR) {
            __define(__module.exports, __require, __module);
        }
        else {
            cc.registerModuleFunc(__filename, function () {
                __define(__module.exports, __require, __module);
            });
        }
        })();
        //# sourceMappingURL=taskPrefab.js.map
        